//
//  YiYuanMainViewController.m
//  1243
//
//  Created by ym on 16/6/29.
//  Copyright © 2016年 1243. All rights reserved.
//

#import "YiYuanMainViewController.h"
#import "BottomView.h"
#import "MerchandiseVC.h"
#import "ShuoMingView.h"
#import "MainDetailView.h"
#import "DuoBaoXinxiViewController.h"
@interface YiYuanMainViewController ()

@end

@implementation YiYuanMainViewController
{
    BottomView *backView;
    UIView *btView;
    ShuoMingView *smView;
    MainDetailView      *mainTBView;
    UIButton *btn;
    UIButton *btn1;
    UIButton *btn2;
    DuoBaoXinxiViewController *duoBaovc;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"一元夺宝";
    self.navigationController.navigationBar.translucent = NO;
    self.view.backgroundColor = [UIColor whiteColor];


    
    [self creatLunbO];
    [self createUI];
    [self jumpToDetail];
    [self backMain];
    [self jumpTodingdan];
}


- (void)creatLunbO{
    NSArray *image = @[
                       [UIImage imageNamed:@"bot_1"],
                       [UIImage imageNamed:@"banner_bot1_boom"],
                       [UIImage imageNamed:@"bot_2"],
                       [UIImage imageNamed:@"bot_3"]
                       ];
    UIScrollView *scorllView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 130*NORMHEIGHT)];
    scorllView.backgroundColor = [UIColor greenColor];
    [self.view addSubview:scorllView];
    // 边缘弹动 效果 bounces
    scorllView.bounces = NO;
    // 整页翻动 pagingEnable
    scorllView.pagingEnabled = YES;
    // 允许滚动
    scorllView.scrollEnabled = YES;
    // 快速滚到当前页面顶端 (点击状态栏时) scrollToTop
    scorllView.scrollsToTop = YES;
    // 隐藏滚动条
    scorllView.showsHorizontalScrollIndicator = YES;  //横向
    scorllView.showsVerticalScrollIndicator = YES;   // 纵向s
    // 自定义滚动条样式
    scorllView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    scorllView.contentSize = CGSizeMake(WIDTH * image.count, 130*NORMHEIGHT);
    
    for (NSInteger i = 0; i < image.count; i++) {
        UIImageView *a = [[UIImageView alloc] init];
        [scorllView addSubview:a];
        a.image = image[i];
        a.frame = CGRectMake(WIDTH *i, 0, WIDTH, 180*NORMHEIGHT);
    }
    
    UILabel *XXXlabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 130*NORMHEIGHT, WIDTH, 30*NORMHEIGHT)];
    [self.view addSubview:XXXlabel];
    XXXlabel.text = @"XXXXXX 夺宝";
    UIImageView *LOGO = [[UIImageView alloc] initWithFrame:CGRectMake(12, 135*NORMHEIGHT, 25, 25*NORMHEIGHT)];
    [self.view addSubview:LOGO];
    LOGO.image = [UIImage imageNamed:@"XXXXX_AAA02"];
}


- (void)createUI {

    backView = [[BottomView alloc]initWithFrame:CGRectMake(0, 155*NORMHEIGHT, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-218)];
    //下面按钮有55的高度
 
    [self.view addSubview:backView];
    btView = [[UIView alloc]initWithFrame:CGRectMake(0, HEIGHT - 60 - 64, WIDTH, 60)];
    [self.view addSubview:btView];
    btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:@"夺宝" forState:UIControlStateNormal];
    btn.frame = CGRectMake( 0, 0, WIDTH/3, 60);
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btn.backgroundColor = [UIColor colorWithRed:228/255.0 green:229/255.0 blue:234/255.0 alpha:1];
    [btn addTarget:self action:@selector(touchUpAction:) forControlEvents:UIControlEventTouchUpInside];
    [btView addSubview:btn];
    
    btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn1 setTitle:@"说明" forState:UIControlStateNormal];
    btn1.frame = CGRectMake( WIDTH/3, 0, WIDTH/3, 60);
    [btn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btn1.backgroundColor = [UIColor whiteColor];
    [btn1 addTarget:self action:@selector(touchUpActionOne:) forControlEvents:UIControlEventTouchUpInside];
    [btView addSubview:btn1];
    
    btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn2 setTitle:@"我的" forState:UIControlStateNormal];
    btn2.frame = CGRectMake( WIDTH/3*2, 0, WIDTH/3, 60);
    [btn2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btn2.backgroundColor = [UIColor whiteColor];
    [btn2 addTarget:self action:@selector(touchUpActionTwo:) forControlEvents:UIControlEventTouchUpInside];
    [btView addSubview:btn2];

    
    
    smView = [[ShuoMingView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 64 -60)];
    smView.hidden = YES;
    [self.view addSubview:smView];
    
    mainTBView = [[MainDetailView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 64 - 60)];
    mainTBView.hidden = YES;
    [self.view addSubview:mainTBView];
    
}

- (void)touchUpAction:(UIButton *)sender {
        NSLog(@"1");
        self.title = @"一元夺宝";
        backView.hidden = NO;
        smView.hidden = YES;
        mainTBView.hidden = YES;
    sender.backgroundColor = [UIColor colorWithRed:228/255.0 green:229/255.0 blue:234/255.0 alpha:1];
    btn1.backgroundColor = [UIColor whiteColor];
    btn2.backgroundColor = [UIColor whiteColor];
}

- (void)touchUpActionOne:(UIButton *)sender {
    NSLog(@"2");
    self.title = @"说明";
    smView.hidden = NO;
    backView.hidden = YES;
    mainTBView.hidden = YES;
    [self.view bringSubviewToFront:btView];
    sender.backgroundColor = [UIColor colorWithRed:228/255.0 green:229/255.0 blue:234/255.0 alpha:1];
    btn.backgroundColor = [UIColor whiteColor];
    btn2.backgroundColor = [UIColor whiteColor];

}

- (void)touchUpActionTwo:(UIButton *)sender {
    NSLog(@"3");
    self.title = @"我的";
    smView.hidden = YES;
    mainTBView.hidden = NO;
    [self.view bringSubviewToFront:btView];
    sender.backgroundColor = [UIColor colorWithRed:228/255.0 green:229/255.0 blue:234/255.0 alpha:1];
    btn.backgroundColor = [UIColor whiteColor];
    btn1.backgroundColor = [UIColor whiteColor];
}

#pragma mark  ----  返回夺宝
- (void)backMain {
    __weak __typeof(self)weakSelf = self;

    mainTBView.jumpToMainBlock = ^void() {
        NSLog(@"就问你走不走");
        weakSelf.title = @"一元夺宝";
        backView.hidden = NO;
        smView.hidden = YES;
        mainTBView.hidden = YES;
        btn.backgroundColor = [UIColor colorWithRed:228/255.0 green:229/255.0 blue:234/255.0 alpha:1];
        btn1.backgroundColor = [UIColor whiteColor];
        btn2.backgroundColor = [UIColor whiteColor];

    };
}

- (void)viewWillAppear:(BOOL)animated {
    [self dingDanBack];
}

- (void)dingDanBack {
            self.title = @"一元夺宝";
            backView.hidden = NO;
            smView.hidden = YES;
            mainTBView.hidden = YES;
            btn.backgroundColor = [UIColor colorWithRed:228/255.0 green:229/255.0 blue:234/255.0 alpha:1];
            btn1.backgroundColor = [UIColor whiteColor];
            btn2.backgroundColor = [UIColor whiteColor];
}


#pragma mark --- 跳转商品详情
- (void)jumpToDetail {
    __weak typeof(self) _weakself = self;
    backView.jumpDetailBlock = ^void() {
        MerchandiseVC *vc = [[MerchandiseVC alloc]init];
        [_weakself.navigationController pushViewController:vc animated:YES];
    };
}

#pragma mark -- 订单跳转方法

- (void)jumpTodingdan {
    __weak typeof(self) _weakself = self;
    mainTBView.dingdanBlock = ^void() {
        duoBaovc = [[DuoBaoXinxiViewController alloc]init];
        [_weakself.navigationController pushViewController:duoBaovc animated:YES];
    };
}



@end
